package net.thxjj.adminServer.mongodao;

import net.thxjj.adminServer.entity.LoginHadleEvent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MongoLoginHandleDao {
    @Autowired
    private MongoTemplate mongoTemplate;

    //导入所有数据
    public void saveAllData(List<LoginHadleEvent> list){
        mongoTemplate.insert(list, LoginHadleEvent.class);
    }


    public List<LoginHadleEvent> getAllLoginHandleInfo(String device_id){
        Query query = new Query(Criteria.where("deviceId").is(device_id));
        query.with(new Sort(Sort.Direction.ASC,"timestamp"));
        return mongoTemplate.find(query,LoginHadleEvent.class);
    }

    public void saveLoginHadleEvent(LoginHadleEvent loginHadleEvent){
        mongoTemplate.save(loginHadleEvent);
    }
}
